% stratified random sampling by district

district_classes = unique(data{:,5});
nrep = 1000;

for j = 1:nrep

    final_index = [];

    for i = 1:numel(district_classes)
        all_index = find(strcmp(data{:,5}, district_classes(i)));
        sample_index = datasample(all_index, floor(numel(all_index) * 50/100), 'replace', false);

        final_index = [final_index sample_index'];
    end

    q1(j) = sum(data{final_index,6});
    q2(j) = sum(data{final_index,7});
    q3(j) = sum(data{final_index,8});
    q4(j) = sum(data{final_index,9});
end

mean(q1)/numel(final_index) * 100
mean(q2)/numel(final_index) * 100
mean(q3)/numel(final_index) * 100
mean(q4)/numel(final_index) * 100